.class public Lnet/oauth/server/OAuthServlet;
.super Ljava/lang/Object;
.source "OAuthServlet.java"


# static fields
.field private static final PROBLEM_TO_HTTP_CODE:Ljava/util/Map;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/Integer;",
            ">;"
        }
    .end annotation
.end field

.field private static final SC_FORBIDDEN:Ljava/lang/Integer;


# direct methods
.method static constructor <clinit>()V
    .locals 2

    .prologue
    .line 108
    new-instance v0, Ljava/lang/Integer;

    const/16 v1, 0x193

    invoke-direct {v0, v1}, Ljava/lang/Integer;-><init>(I)V

    sput-object v0, Lnet/oauth/server/OAuthServlet;->SC_FORBIDDEN:Ljava/lang/Integer;

    .line 111
    sget-object v0, Lnet/oauth/OAuth$Problems;->TO_HTTP_CODE:Ljava/util/Map;

    sput-object v0, Lnet/oauth/server/OAuthServlet;->PROBLEM_TO_HTTP_CODE:Ljava/util/Map;

    return-void
.end method

.method public constructor <init>()V
    .locals 0

    .prologue
    .line 33
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method public static getMessage(Ljavax/servlet/http/HttpServletRequest;Ljava/lang/String;)Lnet/oauth/OAuthMessage;
    .locals 2
    .parameter "request"
    .parameter "URL"

    .prologue
    .line 49
    if-nez p1, :cond_0

    .line 50
    invoke-interface {p0}, Ljavax/servlet/http/HttpServletRequest;->getRequestURL()Ljava/lang/StringBuffer;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object p1

    .line 52
    :cond_0
    const/16 v1, 0x3f

    invoke-virtual {p1, v1}, Ljava/lang/String;->indexOf(I)I

    move-result v0

    .line 53
    .local v0, q:I
    if-ltz v0, :cond_1

    .line 54
    const/4 v1, 0x0

    invoke-virtual {p1, v1, v0}, Ljava/lang/String;->substring(II)Ljava/lang/String;

    move-result-object p1

    .line 58
    :cond_1
    new-instance v1, Lnet/oauth/server/HttpRequestMessage;

    invoke-direct {v1, p0, p1}, Lnet/oauth/server/HttpRequestMessage;-><init>(Ljavax/servlet/http/HttpServletRequest;Ljava/lang/String;)V

    return-object v1
.end method

.method public static getRequestURL(Ljavax/servlet/http/HttpServletRequest;)Ljava/lang/String;
    .locals 3
    .parameter "request"

    .prologue
    .line 63
    invoke-interface {p0}, Ljavax/servlet/http/HttpServletRequest;->getRequestURL()Ljava/lang/StringBuffer;

    move-result-object v1

    .line 64
    .local v1, url:Ljava/lang/StringBuffer;
    invoke-interface {p0}, Ljavax/servlet/http/HttpServletRequest;->getQueryString()Ljava/lang/String;

    move-result-object v0

    .line 65
    .local v0, queryString:Ljava/lang/String;
    if-eqz v0, :cond_0

    .line 66
    const-string v2, "?"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {v2, v0}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    .line 68
    :cond_0
    invoke-virtual {v1}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    return-object v2
.end method

.method public static handleException(Ljavax/servlet/http/HttpServletResponse;Ljava/lang/Exception;Ljava/lang/String;)V
    .locals 1
    .parameter "response"
    .parameter "e"
    .parameter "realm"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;,
            Ljavax/servlet/ServletException;
        }
    .end annotation

    .prologue
    .line 73
    const/4 v0, 0x1

    invoke-static {p0, p1, p2, v0}, Lnet/oauth/server/OAuthServlet;->handleException(Ljavax/servlet/http/HttpServletResponse;Ljava/lang/Exception;Ljava/lang/String;Z)V

    .line 74
    return-void
.end method

.method public static handleException(Ljavax/servlet/http/HttpServletResponse;Ljava/lang/Exception;Ljava/lang/String;Z)V
    .locals 6
    .parameter "response"
    .parameter "e"
    .parameter "realm"
    .parameter "sendBody"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;,
            Ljavax/servlet/ServletException;
        }
    .end annotation

    .prologue
    const/4 v5, 0x0

    .line 79
    instance-of v3, p1, Lnet/oauth/OAuthProblemException;

    if-eqz v3, :cond_3

    move-object v2, p1

    .line 80
    check-cast v2, Lnet/oauth/OAuthProblemException;

    .line 81
    .local v2, problem:Lnet/oauth/OAuthProblemException;
    invoke-virtual {v2}, Lnet/oauth/OAuthProblemException;->getParameters()Ljava/util/Map;

    move-result-object v3

    const-string v4, "HTTP status"

    invoke-interface {v3, v4}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    .line 82
    .local v0, httpCode:Ljava/lang/Object;
    if-nez v0, :cond_0

    .line 83
    sget-object v3, Lnet/oauth/server/OAuthServlet;->PROBLEM_TO_HTTP_CODE:Ljava/util/Map;

    invoke-virtual {v2}, Lnet/oauth/OAuthProblemException;->getProblem()Ljava/lang/String;

    move-result-object v4

    invoke-interface {v3, v4}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    .line 85
    :cond_0
    if-nez v0, :cond_1

    .line 86
    sget-object v0, Lnet/oauth/server/OAuthServlet;->SC_FORBIDDEN:Ljava/lang/Integer;

    .line 88
    .end local v0           #httpCode:Ljava/lang/Object;
    :cond_1
    invoke-interface {p0}, Ljavax/servlet/http/HttpServletResponse;->reset()V

    .line 89
    invoke-virtual {v0}, Ljava/lang/Object;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-static {v3}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v3

    invoke-interface {p0, v3}, Ljavax/servlet/http/HttpServletResponse;->setStatus(I)V

    .line 90
    new-instance v1, Lnet/oauth/OAuthMessage;

    invoke-virtual {v2}, Lnet/oauth/OAuthProblemException;->getParameters()Ljava/util/Map;

    move-result-object v3

    invoke-interface {v3}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v3

    invoke-direct {v1, v5, v5, v3}, Lnet/oauth/OAuthMessage;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/util/Collection;)V

    .line 92
    .local v1, message:Lnet/oauth/OAuthMessage;
    const-string v3, "WWW-Authenticate"

    invoke-virtual {v1, p2}, Lnet/oauth/OAuthMessage;->getAuthorizationHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    invoke-interface {p0, v3, v4}, Ljavax/servlet/http/HttpServletResponse;->addHeader(Ljava/lang/String;Ljava/lang/String;)V

    .line 94
    if-eqz p3, :cond_2

    .line 95
    invoke-virtual {v1}, Lnet/oauth/OAuthMessage;->getParameters()Ljava/util/List;

    move-result-object v3

    invoke-static {p0, v3}, Lnet/oauth/server/OAuthServlet;->sendForm(Ljavax/servlet/http/HttpServletResponse;Ljava/lang/Iterable;)V

    .line 106
    :cond_2
    return-void

    .line 97
    .end local v1           #message:Lnet/oauth/OAuthMessage;
    .end local v2           #problem:Lnet/oauth/OAuthProblemException;
    :cond_3
    instance-of v3, p1, Ljava/io/IOException;

    if-eqz v3, :cond_4

    .line 98
    check-cast p1, Ljava/io/IOException;

    .end local p1
    throw p1

    .line 99
    .restart local p1
    :cond_4
    instance-of v3, p1, Ljavax/servlet/ServletException;

    if-eqz v3, :cond_5

    .line 100
    check-cast p1, Ljavax/servlet/ServletException;

    .end local p1
    throw p1

    .line 101
    .restart local p1
    :cond_5
    instance-of v3, p1, Ljava/lang/RuntimeException;

    if-eqz v3, :cond_6

    .line 102
    check-cast p1, Ljava/lang/RuntimeException;

    .end local p1
    throw p1

    .line 104
    .restart local p1
    :cond_6
    new-instance v3, Ljavax/servlet/ServletException;

    invoke-direct {v3, p1}, Ljavax/servlet/ServletException;-><init>(Ljava/lang/Throwable;)V

    throw v3
.end method

.method public static htmlEncode(Ljava/lang/String;)Ljava/lang/String;
    .locals 6
    .parameter "s"

    .prologue
    .line 129
    if-nez p0, :cond_0

    .line 130
    const/4 v5, 0x0

    .line 154
    :goto_0
    return-object v5

    .line 132
    :cond_0
    new-instance v2, Ljava/lang/StringBuilder;

    invoke-virtual {p0}, Ljava/lang/String;->length()I

    move-result v5

    invoke-direct {v2, v5}, Ljava/lang/StringBuilder;-><init>(I)V

    .line 133
    .local v2, html:Ljava/lang/StringBuilder;
    invoke-virtual {p0}, Ljava/lang/String;->toCharArray()[C

    move-result-object v0

    .local v0, arr$:[C
    array-length v4, v0

    .local v4, len$:I
    const/4 v3, 0x0

    .local v3, i$:I
    :goto_1
    if-ge v3, v4, :cond_1

    aget-char v1, v0, v3

    .line 134
    .local v1, c:C
    sparse-switch v1, :sswitch_data_0

    .line 150
    invoke-virtual {v2, v1}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

    .line 133
    :goto_2
    add-int/lit8 v3, v3, 0x1

    goto :goto_1

    .line 136
    :sswitch_0
    const-string v5, "&lt;"

    invoke-virtual {v2, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    goto :goto_2

    .line 139
    :sswitch_1
    const-string v5, "&gt;"

    invoke-virtual {v2, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    goto :goto_2

    .line 142
    :sswitch_2
    const-string v5, "&amp;"

    invoke-virtual {v2, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    goto :goto_2

    .line 147
    :sswitch_3
    const-string v5, "&quot;"

    invoke-virtual {v2, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    goto :goto_2

    .line 154
    .end local v1           #c:C
    :cond_1
    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    goto :goto_0

    .line 134
    nop

    :sswitch_data_0
    .sparse-switch
        0x22 -> :sswitch_3
        0x26 -> :sswitch_2
        0x3c -> :sswitch_0
        0x3e -> :sswitch_1
    .end sparse-switch
.end method

.method public static sendForm(Ljavax/servlet/http/HttpServletResponse;Ljava/lang/Iterable;)V
    .locals 1
    .parameter "response"
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljavax/servlet/http/HttpServletResponse;",
            "Ljava/lang/Iterable",
            "<+",
            "Ljava/util/Map$Entry;",
            ">;)V"
        }
    .end annotation

    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 116
    .local p1, parameters:Ljava/lang/Iterable;,"Ljava/lang/Iterable<+Ljava/util/Map$Entry;>;"
    invoke-interface {p0}, Ljavax/servlet/http/HttpServletResponse;->resetBuffer()V

    .line 117
    const-string v0, "application/x-www-form-urlencoded;charset=UTF-8"

    invoke-interface {p0, v0}, Ljavax/servlet/http/HttpServletResponse;->setContentType(Ljava/lang/String;)V

    .line 119
    invoke-interface {p0}, Ljavax/servlet/http/HttpServletResponse;->getOutputStream()Ljavax/servlet/ServletOutputStream;

    move-result-object v0

    invoke-static {p1, v0}, Lnet/oauth/OAuth;->formEncode(Ljava/lang/Iterable;Ljava/io/OutputStream;)V

    .line 120
    return-void
.end method
